package com.junt.library.view;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.junt.library.MediaSelector;
import com.junt.library.core.QueryType;
import com.junt.library.R;
import com.junt.library.model.Media;

import java.util.List;

/**
 * 图片、视频选择
 */
public class MediaActivity extends BaseMediaActivity {

    private GridFragment gridFragment;

    @Override
    int getLayoutResId() {
        return R.layout.activity_media;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void init() {
        initView();
    }

    @Override
    protected void onDataReady(List<Media> medias) {
        gridFragment.setNewData(medias);
    }

    private void initView() {
        TextView tvTitle = findViewById(R.id.tvTitle);
        tvTitle.setText(MediaSelector.getInstance().getQueryType() == QueryType.IMAGE ? "图片选择" : "视频选择");
        TextView tvClose = findViewById(R.id.tvClose);
        tvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MediaSelector.getInstance().setNoneResult(MediaActivity.this);
            }
        });
        TextView tvConfirm = findViewById(R.id.tvConfirm);
        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MediaSelector.getInstance().setResult(MediaActivity.this, gridFragment.getSelectedMedias());
            }
        });
        gridFragment = GridFragment.newInstance(MediaSelector.getInstance().getQueryType().ordinal());
        getSupportFragmentManager().beginTransaction().add(R.id.flGrid, gridFragment).commit();
    }

}